﻿using System;
using Newtonsoft.Json;

namespace OrkutAPILibrary.Entities
{
    /// <summary>
    /// Orkut Scrap
    /// </summary>
    public class OrkutScrap
    {
        /// <summary>
        /// Gets or sets the scrap body.
        /// </summary>
        /// <value>The scrap body.</value>
        [JsonProperty(PropertyName = "body")]
        public string ScrapBody { get; set; }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>The type.</value>
        [JsonProperty(PropertyName = "type")]
        public string Type { get; set; }

        /// <summary>
        /// Gets or sets from user id.
        /// </summary>
        /// <value>From user id.</value>
        [JsonProperty(PropertyName = "fromUserId")]
        public string FromUserId { get; internal set; }

        /// <summary>
        /// Gets or sets the scrap id.
        /// </summary>
        /// <value>The scrap id.</value>
        [JsonProperty(PropertyName = "id")]
        public string ScrapId { get; internal set; }

        /// <summary>
        /// Gets or sets the time.
        /// </summary>
        /// <value>The time.</value>
        public DateTime Time { get; internal set; }

        internal static readonly DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

        [JsonProperty(PropertyName = "time")]
        internal string _time
        {
            get
            {
                return (Time - unixEpoch).TotalSeconds.ToString();
            }
            set
            {
                Time = unixEpoch.AddSeconds(Convert.ToInt32(value));
            }
        }

        /// <summary>
        /// Gets or sets from user profile.
        /// </summary>
        /// <value>From user profile.</value>
        [JsonProperty(PropertyName = "fromUserProfile")]
        public OrkutPerson FromUserProfile { get; internal set; }
    }
}
